home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10751 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  5.1 KB

  1. Path: ix.netcom.com!netnews
  2. From: Mike Girou <girou@parashift.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: PLEASE Help! :(
  5. Date: Sat, 09 Mar 1996 16:28:24 -0600
  6. Organization: Paradigm Shift, Inc.
  7. Message-ID: <31420608.6750@parashift.com>
  8. References: <4hsqre$4d7@deadbird.db.erau.edu>
  9. NNTP-Posting-Host: ix-dfw13-10.ix.netcom.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-NETCOM-Date: Sat Mar 09  2:28:56 PM PST 1996
  14. X-Mailer: Mozilla 2.0 (Win95; I)
  15.  
  16. Hi,
  17.  
  18. Dump out the data as you read it in and ask yourself how strings are
  19. delimited.  This will get you started on the right track.
  20.  
  21. Part of the educational process comes from struggling with things you
  22. don't understand, and learning how to figure things out without asking
  23. for inappropriate help.  You are short-changing yourself if you don't
  24. learn how to learn.  It's okay to ask for occasional clues, usually
  25. from fellow students or the instructor, but that's it.
  26.  
  27. If you feel that it is proper to post to a newsgroup, post to the
  28. correct newsgroup.  This is comp.lang.c++ for the c++ language, not
  29. the c language.
  30.  
  31. We've all felt that same frustrations that you are feeling now, and
  32. I suspect we are all sympathetic to your call for help.  But, please,
  33. for your own good, don't look for help with homework problems unless
  34. it is something really obscure or specialized.  Then, ask your
  35. instructor and if he doesn't know the answer, he can post to the
  36. proper newsgroup for help.
  37.  
  38. Mike
  39.  
  40.  
  41.  
  42. Konrad Kochan wrote:
  43. > Howdy.. I have a program to write, but I'm clueless... Now I could
  44. > give you a 100 excuses and blame the instructor (and I should cause
  45. > all of it would be true.. :)
  46. > Anyways, I'm clueless.. can someone, a good samaritan (or someone just
  47. > bored..) help me out!
  48. > Here is the program statement..
  49. > Write a C program to sort, using any sorting method, a text file
  50. > named RECORDS.DAT, of unknown length, of records organized as follows:
  51. > Field 1.  Contains an integer.
  52. > Field 2.  Contains a string of exactly 20 characters.
  53. > Field 3.  Contains a float followed by a newline character.
  54. > Example of file organization:
  55. > 234 Numa Chaikin        33000.0
  56. > 234 Numa Chaikin        33000.0
  57. >  75 advertisements      55.55
  58. > 901 Shepard             15255.5
  59. >   3 Brook               120050.0
  60. > 888 non-descriptive     0.0
  61. > Sorting has to be done lexicographically, that is, by the second field
  62. > using alphabetical order.  This means that:
  63. > 1. Upper-case and lower-case letters should be treated identically.
  64. >    For example, the right order for a part of the list above is:
  65. >    888 non-descriptive 0.0
  66. >    234 Numa Chaikin 33000.0
  67. > 2. The only punctuation sign used in strings is a dash '-', which
  68. >    should be ignored in sorting (but not removed from words).
  69. > ~
  70. > ~
  71. > ~
  72. > ~
  73. > And here is what I got so far.. which DOESN'T work (right or otherwise, I
  74. > can't even get the program to scan the right fields from the file.. :(
  75. > #include <stdio.h>
  76. > #include <stdlib.h>
  77. > #include <string.h>
  78. > /* Global Variable Definition */
  79. > int IntArr[512][5];
  80. > char WordsArr1[512][10];
  81. > char WordsArr2[512][10];
  82. > float FloatArr[512][5];
  83. > char inbuff[80];
  84. > int index=0;
  85. > /* Function declaration */
  86. > void Welcome(void);
  87. > void Goodbye(void);
  88. > main()
  89. > {
  90. > main()
  91. > {
  92. > /* Next function opens a file, if the file is missing, it prints
  93. >  an error message */
  94. > int i;
  95. >  FILE * fin, * fout;
  96. >     if (!(fin = fopen("RECORDS.DAT", "r")))
  97. >          {
  98. >         printf("Something is wrong: Probably file missing.\n");
  99. >         exit(1);   /* Program exits here if file is missing. */
  100. >           }
  101. >         printf("\nInput File = RECORDS.DAT\n");
  102. > /* This function prints a Welcome message */
  103. > /* Welcome(); */
  104. > /* This function scans in the array */
  105. >         while (fgets(inbuff,80,fin) !=NULL)
  106. > {
  107. > sscanf(inbuff,"%d %s %s %4.2f", &IntArr[index],&WordsArr1[index],&WordsArr2[inde
  108. > x],&FloatArr[index]);
  109. > {
  110. > sscanf(inbuff,"%d %s %s %4.2f", &IntArr[index],&WordsArr1[index],&WordsArr2[inde
  111. > x],&FloatArr[index]);
  112. > index++;
  113. > }
  114. > /* Opens the output file */
  115. > if (!(fout = fopen("test", "w")))
  116. >          {
  117. >         printf("Something is wrong: File might be write protected.\n");
  118. >         exit(1);   /* Program exits here if file can't be opened. */
  119. >           }
  120. >     for (i=0; i<index; i++)
  121. >         fprintf(fout, "%d %s %s %4.2f\n",  IntArr[i], WordsArr1[i],WordsArr2[i],
  122. >         FloatArr[i]);
  123. > /* Prints the sorted array to the screen */
  124. >     for (i=0; i<index; i++)
  125. >         printf("Original array: %d %s %s %4.2f \n", IntArr[i],WordsArr1[i],
  126. >     for (i=0; i<index; i++)
  127. >         printf("Original array: %d %s %s %4.2f \n", IntArr[i],WordsArr1[i],
  128. > WordsArr2[i],FloatArr[i]);
  129. > fclose(fin);
  130. > fclose(fout);
  131. > }
  132. > ~
  133. > ~
  134. > ~
  135. > ~
  136. > ~
  137. > ~
  138. > ~
  139. > ~
  140. > ~
  141. > ~
  142. > ~
  143. > ~
  144. > ~
  145. > ~
  146. > ~
  147. > If you can either give me hints, rewrite the above, or write a totaly
  148. > new program I would appreciate it.. I know its a lot to ask for (to do some-
  149. > one elses homework pretty much..) but I'm really clueless..
  150. > Thank you in advance!
  151.  
  152. -- 
  153. Mike Girou              girou@parashift.com
  154.